<template>
  <div class="page">
    <div class="title">
      表 A.1 温室气体排放汇总表
    </div>

    <el-table :data="tableData" border>
      <el-table-column prop="name" label="类别" align="center">
        <template slot-scope="scope">
          <div :class="{ 'total': scope.row.tip }">{{ scope.row.name }}</div>
          <div v-if="scope.row.tip">{{ scope.row.tip }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="value" label="数量" align="center" />
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'SummaryTable',
  props: {
    data: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      rowName: {
        newUser: '新用户量',
        totalUser: '总用户量',
        product: '产品量',
        order: '订单量',
        totalResult: '总量',
      },
      tableData: [],
    };
  },
  watch: {
    data: {
      handler(data) {
        console.log(data);
        const nameList = Object.values(this.rowName);
        this.tableData = Object.entries(data).map(([key, value]) => {
          return {
            name: this.rowName[key],
            value: Math.round(value * 100) / 100,
          };
        }).sort((curr, prev) => nameList.indexOf(curr.name) - nameList.indexOf(prev.name));
      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style lang="scss" scoped>
.total {
  font-weight: 600;
}
</style>
